package com.neutech.maplestory.util;

import com.neutech.maplestory.constant.Constant;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @Description: TODO(项目中实现窗口的父类，项目中)
 * @Author ${秦}
 * @Date 2021/1/27 9:28
 */
public class MapleStoryFrame extends Frame {

    public MapleStoryFrame(){}

    /*
    * 初始化当前窗口的方法
    * */
    public void init(){
        this.setIconImage(ImageUtil.getImage("logo"));
        this.setSize(Constant.GAME_WIDTH,Constant.GAME_HEIGHT);
        this.setVisible(true);//可见性
        this.setResizable(false);//不能改变大小
        this.setTitle(Constant.GAME_TITLE);
        this.setLocationRelativeTo(null);
        //关闭窗口的方法
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        //自动重画线程
        new MapleStoryThread().start();
    }
    /*
    * 实现窗口重新绘制的线程内部类
    * */
    class MapleStoryThread extends Thread{
        @Override
        public void run() {
            for(;;){
                repaint();
                try {
                    Thread.sleep(40);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
            }
        }
    }


